package com.itheima.admin.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author :WuJunJie
 * packageName :com.itheima.admin.filter
 * fileName :StaticFilter
 * creationTime :2022-11-06 14:34
 */
@WebFilter("/*")
@Slf4j
//@Component
public class AStaticFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest hsr = (HttpServletRequest) servletRequest;
        String requestURI = hsr.getRequestURI();
//        if (requestURI.endsWith("html") || requestURI.endsWith("js") || requestURI.endsWith("css")) {
//            log.info("静态资源放行");
//            //放行
//            servletRequest.setAttribute("flag", true);
//
//        }
        log.info("静态拦截");
        servletRequest.setAttribute("flag", requestURI.endsWith("html") || requestURI.endsWith("js") || requestURI.endsWith("css"));
        filterChain.doFilter(servletRequest, servletResponse);
    }
}
